package com.hcx.base.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class CreateThreadDemo   {
    public static void main(String[] args) throws Exception{
        //多线程创建方式
        //1 implements Runnable
        /*new Thread(new Runnable() {
            public void run() {
                //我是具体的执行
            }
        });*/
        // 2 new Thread extends Thread
        //3 实现 callable
        Callable<String> callable = new Callable<String>() {
            public String call() throws Exception {
                return "我是返回的内容";
            }
        };
        FutureTask<String> task = new FutureTask<String>(callable);
        Thread callThread = new Thread(task, "我是call线程");
        callThread.start();
        String callResult = task.get();
        System.out.println("返回的内容为:"+callResult);
        System.out.println("我结束了");
    }
}
